#ifndef SHARE_TRANSPORT_H
#define SHARE_TRANSPORT_H

#include <mutex>

#include "FuseServer.h"
#include "ShareSendProcess.h"
#include "ShareRecvProcess.h"
#include "VioSAPI.h"

#define VIRTIO_SERIAL_PORT 3
#define FUSE_SERIAL_PORT 4

#define RECV_DATA_TOTAL_DELAY 5000

class ShareTransport {
public:
    explicit ShareTransport(std::function<HDEVNOTIFY(HANDLE)> registerHandleNotify);
    ~ShareTransport();
    DWORD Init();
    void SendShareMsg(PBYTE hdr, SIZE_T hdrSize, ShareSendProcess* proc);
    BOOL RecvAllData(ShareRecvProcess& recvProcess);
    BOOL CancelIO();
    IFSL* GetFuseServer();
    void DropLeftData();
    HANDLE GetClipboardTransportHandle();
    HANDLE GetFuseServerTransportHandle();
    void SetFuseServerReconnect(BOOL isReconnect);

private:
    BOOL RecvHeader(ShareRecvProcess& recvProcess, DWORD &headerLen, SIZE_T &dataLen);
    BOOL Send(PBYTE buf, DWORD bufLen);
    std::mutex m_mutex;
    VioSAPI m_vios;
    std::unique_ptr<IFSL, void (*)(IFSL*)> m_fuseServer;
    BOOL m_bInitialised;
    HDEVNOTIFY m_clipboardTransNotify;
    HDEVNOTIFY m_fuseServerTransNotify;
    std::function<HDEVNOTIFY(HANDLE)> m_registerHandleNotify;
};

#endif // SHARE_TRANSPORT_H
